//################################################################################################################################//
//##                                                                                                                            ##//
//## This page is designed and developed to implement Make an Appointment  to the Doctor                                                                     ##//
//##                                                                                                                            ##//
//## Author   : Akash Saxena                                                                                                          ##//
//## Dated    : 16 Sep '07                                                                                                   ##//
//##                                                                                                                            ##//
//################################################################################################################################//

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;

public partial class User_MakeAppointment : System.Web.UI.Page
{
    int iUserId = 0;
    int iDoctorid = 0;
    string sUserEmail = "";
    //Create object of Doctor and Manager class.
    Doctor objDoctor = new Doctor();
    Manager objManager = new Manager(true,"ConnectionString");

    protected void Page_Load(object sender, EventArgs e)
    {

        localFunction lfunction = new localFunction();
        lfunction.checkPatientLogin(true);

      if(!Page.IsPostBack)
        {
            lblOutput.Text = "";
        
            if (Session["userID"] != null && Session["userID"].ToString().Trim() != "")
            {

                iUserId = Convert.ToInt32(Session["userID"]);
            }
            else
            {
                iUserId = 0;
            }
                    
            
        }
        if (Session["useremail"] != null && Session["useremail"].ToString().Trim() != "")
        {
            sUserEmail = Session["useremail"].ToString();
        }
        if (!Equals(Request.QueryString["Id"], null))
        {
            if (Manager.IsNumeric(Request.QueryString["Id"].ToString()))
            {
                iDoctorid = Convert.ToInt32(Request.QueryString["Id"]);
            }
        }
           

    }
    protected void btnMakeAppointment_Click(object sender, EventArgs e)
    {

        string ToEmail = "";
        string MessageBody = string.Empty;


        SqlDataReader objDataReader = null;

        objDataReader = objManager.ExecuteQuery("select Email from tbl_Doctors where id=" + iDoctorid);

        if (objDataReader.HasRows)
        {
            objDataReader.Read();
            ToEmail = objDataReader["Email"].ToString();
            if (ToEmail.Length.Equals(0))
            {
                lblMsg.Text = " Message can not send. ";
                return;
            }

        }


        if (Session["LoginName"] != null && Session["LoginName"].ToString().Trim() != "")
        {
            MessageBody = Session["LoginName"].ToString() + " " + "is requesting for an appointment. <br>";
        }

        MessageBody += "Comments: <br>" + txtComments.Text;

        if (objManager.sendMail(MessageBody, ToEmail, Session["LoginName"].ToString(),
                "Appointment Request", sUserEmail, ""))
        {
            lblOutput.Text = "Appointment Request has been sent successfuly";

            txtComments.Text = "";
        }
        else
        {
            lblOutput.Text = "Appointment Request sent failure! Please try again later.";

        }
        objDataReader.Close();
        objDataReader.Dispose();
    }
}
